package com.pay.ioopos.support.serialport.custom;

/**
 * 指令业务类型
 * @author moyq5
 * @since 2022/7/26
 */
public enum SerialPortPayCmdType {
    /**
     * 设备侦测
     */
    VERSION(new SerialPortPayCmd4VersionDer()),
    /**
     * 键盘输入
     */
    KEY_EVENT(new SerialPortPayCmd4KeyEventDer(), new SerialPortPayCmd4KeyEventCer()),
    /**
     * 发起收款
     */
    PAY_SUBMIT(new SerialPortPayCmd4SubmitDer(), new SerialPortPayCmd4SubmitCer()),
    /**
     * 取消收款
     */
    PAY_CANCEL(new SerialPortPayCmd4CancelDer(), new SerialPortPayCmd4CancelCer()),
    /**
     * 收款状态
     */
    PAY_STATUS(),
    /**
     * 退款
     */
    PAY_REFUND(new SerialPortPayCmd4RefundDer(), new SerialPortPayCmd4RefundCer());

    private CustomCmdDeserializer<?> deserializer;
    private SerialPortPayCmdConsumer consumer;

    SerialPortPayCmdType() {
    }

    SerialPortPayCmdType(CustomCmdDeserializer<?> deserializer) {
        this.deserializer = deserializer;
    }

    SerialPortPayCmdType(SerialPortPayCmdConsumer consumer) {
        this.consumer = consumer;
    }

    SerialPortPayCmdType(CustomCmdDeserializer<?> deserializer, SerialPortPayCmdConsumer consumer) {
        this.deserializer = deserializer;
        this.consumer = consumer;
    }

    public Object deserialize(byte[] data) {
        if (null == deserializer) {
            return null;
        }
        return deserializer.deserialize(data);
    }

    public void consume(byte[] data) {
        if (null == consumer) {
            return;
        }
        consumer.consume(data);
    }
}
